﻿using System;
using System.Collections.Generic;
using System.ComponentModel;

namespace DataConvertLib
{
	/// <summary>
	/// Double类型数据转换类
	/// </summary>
	// Token: 0x02000006 RID: 6
	[Description("Double类型数据转换类")]
	public class DoubleLib
	{
		/// <summary>
		/// 将字节数组中某8个字节转换成Double类型
		/// </summary>
		/// <param name="value">字节数组</param>
		/// <param name="start">开始位置</param>
		/// <param name="dataFormat">字节顺序</param>
		/// <returns>Double类型数值</returns>
		// Token: 0x0600004C RID: 76 RVA: 0x00003A50 File Offset: 0x00001C50
		[Description("将字节数组中某8个字节转换成Double类型")]
		public static double GetDoubleFromByteArray(byte[] value, int start = 0, DataFormat dataFormat = DataFormat.ABCD)
		{
			byte[] value2 = ByteArrayLib.Get8BytesFromByteArray(value, start, dataFormat);
			return BitConverter.ToDouble(value2, 0);
		}

		/// <summary>
		/// 将字节数组转换成Double数组
		/// </summary>
		/// <param name="value">字节数组</param>
		/// <param name="dataFormat">字节顺序</param>
		/// <returns>Double数组</returns>
		// Token: 0x0600004D RID: 77 RVA: 0x00003A74 File Offset: 0x00001C74
		[Description("将字节数组转换成Double数组")]
		public static double[] GetDoubleArrayFromByteArray(byte[] value, DataFormat dataFormat = DataFormat.ABCD)
		{
			bool flag = value == null;
			if (flag)
			{
				throw new ArgumentNullException("检查数组长度是否为空");
			}
			bool flag2 = value.Length % 8 != 0;
			if (flag2)
			{
				throw new ArgumentNullException("检查数组长度是否为8的倍数");
			}
			double[] array = new double[value.Length / 8];
			for (int i = 0; i < value.Length / 8; i++)
			{
				array[i] = DoubleLib.GetDoubleFromByteArray(value, 8 * i, dataFormat);
			}
			return array;
		}

		/// <summary>
		/// 将Double字符串转换成双精度浮点型数组
		/// </summary>
		/// <param name="value">Double字符串</param>
		/// <param name="spilt">分割符</param>
		/// <returns>双精度浮点型数组</returns>
		// Token: 0x0600004E RID: 78 RVA: 0x00003AE4 File Offset: 0x00001CE4
		[Description("将Double字符串转换成双精度浮点型数组")]
		public static double[] GetDoubleArrayFromString(string value, string spilt = " ")
		{
			value = value.Trim();
			List<double> list = new List<double>();
			double[] result;
			try
			{
				bool flag = value.Contains(spilt);
				if (flag)
				{
					string[] array = value.Split(new string[]
					{
						spilt
					}, StringSplitOptions.RemoveEmptyEntries);
					foreach (string text in array)
					{
						list.Add(Convert.ToDouble(text.Trim()));
					}
				}
				else
				{
					list.Add(Convert.ToDouble(value.Trim()));
				}
				result = list.ToArray();
			}
			catch (Exception ex)
			{
				throw new ArgumentNullException("数据转换失败：" + ex.Message);
			}
			return result;
		}
	}
}
